Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDBS-Spring20-Fudan/assignment2/readme/ #45

Open
utterances-bot opened this issue Mar 21, 2020 · 15 comments
Open

IDBS-Spring20-Fudan/assignment2/readme/ #45

utterances-bot opened this issue Mar 21, 2020 · 15 comments

Comments

@utterances-bot
Copy link

Instruction - IDBS-Spring20-Fudan

Course website for introduction to database systems at Fudan University

https://zfhu.ac.cn/IDBS-Spring20-Fudan/assignment2/readme/

Copy link
Contributor

Will the submission upload the username and password of mysql when executing "go run main.go util.go"?

@ichn-hu
Copy link
Collaborator

ichn-hu commented Mar 22, 2020

Will the submission upload the username and password of mysql when executing "go run main.go util.go"?

Running go run main.go util.go won't upload it. But it will be committed when you finish the assignment, this is a good question, indeed there are security concerns, you could create a new mysql user with simplistic password like 123456, as long as you are running mysql at your local machine (i.e. localhost), it should be fine.

The evaluation of your submission for ass2 will not touch the configuration you provided, I'll only take the three functions you wrote.

Copy link

In the first task, I have executed "$ go run main.go utils.go" for many times, however, sometime I get the answer"take xxx ms(usually between 50-100)" while sometime I get the answer "not implemented"(the same code). I am not sure whether it is a normal phenomenon and what causes this problem if my code is wrong , since I have already used closures to get the variables to avoid some mistakes. (I used go func() in the first "for".)

@ichn-hu
Copy link
Collaborator

ichn-hu commented Mar 22, 2020

In the first task, I have executed "$ go run main.go utils.go" for many times, however, sometime I get the answer"take xxx ms(usually between 50-100)" while sometime I get the answer "not implemented"(the same code). I am not sure whether it is a normal phenomenon and what causes this problem if my code is wrong , since I have already used closures to get the variables to avoid some mistakes. (I used go func() in the first "for".)

Take a look at the main.go file, the not implemented error is caused by checking if the table has no data inserted. It might be concurrency problems that causes your insertion failed.

@Tan-YiFan
Copy link
Contributor

On my device, the single-thread version takes about 9 seconds and the concurrent version I wrote takes about 1 second, only 9x. (9,800 queries) However, I didn't use sync.mutex. Instead, I simply use waitgroup. May I ask about the grading on this part? The faster, the higher grade?

@ichn-hu
Copy link
Collaborator

ichn-hu commented Mar 22, 2020

On my device, the single-thread version takes about 9 seconds and the concurrent version I wrote takes about 1 second, only 9x. (9,800 queries) However, I didn't use sync.mutex. Instead, I simply use waitgroup. May I ask about the grading on this part? The faster, the higher grade?

nope, as long as you made it concurrent, you will get the score. However you are encouraged to make it faster by trying more strategies.

9x speed up is not bad. My laptop has 4 cores and 8 thread, and its frequency is quite low, so concurrency has way better performance. In your case, the single thread version already performs reasonably well, the room for improvement is much more limited.

@Tan-YiFan
Copy link
Contributor

GetSocre函数是否有指定的输出顺序?

@ichn-hu
Copy link
Collaborator

ichn-hu commented Mar 23, 2020

GetSocre函数是否有指定的输出顺序?

没有的,评价的时候不会看你的输出,而是调用 GetScore,然后读 Submission 的 score,因此顺序不重要。

Copy link

I meet some problems about "only_full_group_by" in task2, which make my code fail, should I deal with this problem to make my code pass or just leave it and change my code?

@ichn-hu
Copy link
Collaborator

ichn-hu commented Mar 23, 2020

I meet some problems about "only_full_group_by" in task2, which make my code fail, should I deal with this problem to make my code pass or just leave it and change my code?

I didn't get what you mean, either way you have to solve the problem. If you want, you could provide the error message here.

Copy link

panic: Error 1055: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a.submitter' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

I search it on Internet and find some solutions, but the solutions don't relate to the code itself, but mysql settings, so I'm not sure whether I should edit the settings to solve the problem or just change the code.

@ichn-hu
Copy link
Collaborator

ichn-hu commented Mar 23, 2020

panic: Error 1055: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a.submitter' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

I search it on Internet and find some solutions, but the solutions don't relate to the code itself, but mysql settings, so I'm not sure whether I should edit the settings to solve the problem or just change the code.

I have never met this problem before, and I am running MySQL in the default setting. I suggest you to check your SQL more carefully, change your code is always better than change the setting.

Copy link

two slices are deeply equal requires either they point to the same initial entry of the same underlying array or their corresponding elements (up to length) are deeply equal. so "sqlResults [][]map[string]interface{}" and "reflect.DeepEqual(sub.sqlResults[i], sub2.sqlResults[i])" mean if the maps that slices point to are deeply equal, the slices are deeply equal ? while the deeply-equality of the maps have nothing to do with order, the deeply-equality of the slices have nothing to do with order?

@TwistsOfFate
Copy link
Contributor

In Concurrent Comparison Result Insert:

Also as a kind note, sql.DB is not thread-safe, you need multiple sql.DB if you want concurrent access of the database, and figuring out (by search it online) what is closure, and how to pass variable to a closure might be helpful.

However, according to

The returned DB is safe for concurrent use by multiple goroutines and maintains its own pool of idle connections. Thus, the Open function should be called just once. It is rarely necessary to close a DB.

it seems that the DB is safe for concurrent use as long as we limit of the number of connections. I tried sharing a single sql.DB among all the goroutines and it did work on my computer.

I wonder if this was generally considered a safe approach.

@ichn-hu
Copy link
Collaborator

ichn-hu commented Mar 31, 2020

* https://jmoiron.github.io/sqlx/#connectionPool

Thanks a lot for the reminder, I was wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants